#include "Scope.h"
#include "cScene.h"
#include "Globals.h"
#include "Physics.h"


Scope::Scope()
{
	m_x = m_y = 0;
}


Scope::~Scope()
{
}


void Scope::GetVector(Collider * collider, int velocity, float * vx, float * vy)
{
	int * coordinates = collider->GetCoordinates();
	int x0 = coordinates[0];
	int y0 = coordinates[1];
	int xf = coordinates[2];
	int yf = coordinates[3];
	delete(coordinates);
	int shooterX = x0 + (abs(x0 - xf) / 2);
	int shooterY = y0 + (abs(y0 - yf) / 2);
	*vx = m_x - shooterX;
	*vy = m_y - shooterY;
	int module = sqrt(pow(*vx, 2) + pow(*vy, 2));
	*vx = (float)(*vx / module) * velocity;
	*vy = (float)(*vy / module) * velocity;
}

void Scope::Draw(int tex_id)
{
	int x0 = 0;
	int y0 = 100;
	int xf = 100;
	int yf = 0;
	int screen_x, screen_y;

	int x = m_x - WIDTH / 2;
	int y = m_y - HEIGHT / 2;
	screen_x = x + SCENE_Xo;
	screen_y = y + SCENE_Yo + (BLOCK_SIZE - TILE_SIZE);

	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, tex_id);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0);	glVertex2i(screen_x, screen_y);
	glTexCoord2f(1.0, 0.0);	glVertex2i(screen_x + WIDTH, screen_y);
	glTexCoord2f(1.0, 1.0);	glVertex2i(screen_x + WIDTH, screen_y + HEIGHT);
	glTexCoord2f(0.0, 1.0);	glVertex2i(screen_x, screen_y + HEIGHT);
	glEnd();

	glDisable(GL_TEXTURE_2D);
}

void Scope::GetPosition(int * x, int * y)
{
	*x = m_x;
	*y = m_y;
}
void Scope::SetPosition(int x, int y)
{
	m_x = x;
	m_y = y;
}